home *** CD-ROM | disk | FTP | other *** search
/ LineOne ISP Sign-Up 5 / LineOne.iso / assets / cxt / scripts / parentScripts.cst / 00012_dataManager parent.ls < prev    next >
Encoding:
Text File  |  2001-01-27  |  6.6 KB  |  247 lines

  1. -- 2000.03.12
  2. -- Clive Green <clivegreen@atlas.co.uk>
  3.  
  4. ------------------------------------------------------------------------------------------------------
  5.  
  6. -- This is just a repository of programme settings obtained from external text files.
  7.  
  8. -- The access method getData() needs to be passed a list of the form:
  9. -- [#set:<#setName>{,#item:<#itemName>}]
  10.  
  11. -- the method setDataItem needs to be passed a list of the form:
  12. -- [#set:<#setName>,#item:<#itemName>, #value:<#propList>]
  13.  
  14. ------------------------------------------------------------------------------------------------------
  15.  
  16. -- declare properties:
  17. property main           -- main code directory object
  18. property utilityMethods -- miscellaneous functions
  19. property rootPath       -- the runtime parent path of the projector/stub
  20. property dataLibList    -- linear list of linked data castlibs
  21. property dataFiles      -- a list of known data file #references
  22. property dataSet        -- data storage - a propList of propLists!
  23.  
  24. ------------------------------------------------------------------------------------------------------
  25.  
  26. on new me,L
  27.   
  28.   -- (1) extract and check arguments:
  29.   
  30.   -- check for a parameter list:
  31.   if ilk(L) <> #propList then return [#error:#noParamListSupplied, #msg:"dataManager:new"]
  32.   
  33.   -- a reference to the parent codebase is REQUIRED:
  34.   main = L[#main]
  35.   if (ilk(main) <> #instance) then return [#error:#noMainObjectSupplied, #msg:"dataManager:new"]
  36.   
  37.   --------------------
  38.   
  39.   -- store literals:
  40.   
  41.   -- which linked castlibraries contain data used by the programmme?
  42.   dataLibList = ["data"]
  43.   
  44.   --------------------
  45.   
  46.   -- (2) import data held in castlibrary fields:
  47.   
  48.   -- pull in utility methods:
  49.   utilityMethods = main.getUtilityMethods()
  50.   
  51.   -- store internally held data:
  52.   dataSet = [:]
  53.   
  54.   -- recurse over all known data castlibs:
  55.   repeat with i in dataLibList
  56.     
  57.     -- get the ith listed castlib's number:
  58.     c = castlib(i).number
  59.     
  60.     -- recurse over all of library c's field members:
  61.     repeat with j = 1 to the number of members of castlib c
  62.       
  63.       -- examine fields only:
  64.       n = member(j,c).number
  65.       if member(n).type <> #field then next repeat
  66.       
  67.       -- convert each field's text into a data list:
  68.       t = member(n).text
  69.       L = utilityMethods.listFromText(t)
  70.       
  71.       -- stored listing:
  72.       n = symbol(member(n).name)
  73.       dataSet[n] = L
  74.       
  75.     end repeat
  76.     
  77.   end repeat
  78.   
  79.   --------------------
  80.   
  81.   -- pass back my address:
  82.   return me
  83.   
  84.   ----------------------------------------------------------------------------------------------------
  85.   
  86. on setRootPath me,p
  87.   
  88.   -- store the path string supplied as is:
  89.   rootPath = p
  90.   
  91.   ----------------------------------------------------------------------------------------------------
  92.   
  93. on getRootPath me
  94.   
  95.   -- pass back the parent path of the projector/stub:
  96.   return rootPath
  97.   
  98.   ----------------------------------------------------------------------------------------------------
  99.   
  100. on getExternalData me
  101.   
  102.   -- import data held in external text files:
  103.    
  104.   -- (1) obtain the fileIO service:
  105.   xm = main.getXtrasManager()
  106.   fileIO = xm.getFileIOxtra()
  107.    
  108.   if (ilk(fileIO) <> #instance) then return ┬¼
  109.   [#error:#xtraControllerMissing, #msg:"dataManager:new needs fileIOxtra"]
  110.     
  111.   --------------------
  112.   
  113.   -- (2) what text files contain data used by the programme?
  114.   L = []
  115.   add L,#soundFX   
  116.   add L,#conditionElements
  117.   add L,#conditionGroups
  118.   add L,#outcomes 
  119.   add L,#glueCalls
  120.   add L,#callBindings 
  121.   add L,#macInstallerPaths
  122.   add L,#pcInstallerPaths
  123.   
  124.   dataFiles = L
  125.   
  126.   --------------------
  127.   
  128.   -- (3) get a listing of all known filePaths:
  129.   fp = me.getData([#set:#filePaths])
  130.    
  131.   -- we need a valid filePaths listing:
  132.   if stringP(fp[#error]) then return fp
  133.    
  134.   --------------------
  135.   
  136.   -- (4) attempt to acquire all file-based data:
  137.    
  138.   -- process all data files:
  139.   repeat with i in dataFiles
  140.     
  141.     -- what is the filepath of file #i?
  142.     f = fp[i][#filePath]   
  143.     
  144.     -- obtain a platform-specific version of this filePath:
  145.     f = utilityMethods.parseFilePath(f)
  146.      
  147.     -- a valid path string is required:
  148.     if not stringP(f) then return f
  149.     
  150.     --------------------
  151.     
  152.     -- each filePath is given relative to the application's root stub/projector:
  153.     f = rootPath & f
  154.      
  155.     -- attempt to obtain the text for this file:
  156.     t = fileIO.importTextFile([#filePath:f, #type:#readOnly])
  157.     
  158.     -- ALL DATA IS REQUIRED -
  159.     -- fail on first unsuccessful retrieval:
  160.     if not stringP(t) then return t
  161.     
  162.     --------------------
  163.     
  164.     -- now attempt to render a lingo list:
  165.     L = utilityMethods.listFromText(t)
  166.     if not listP(L) then return [#error:#badTextData, #msg:i]
  167.        
  168.     -- add this data as a named item:
  169.     dataSet[i] = L  
  170.     
  171.   end repeat
  172.   
  173.   -- flag successful operation:
  174.   return me
  175.   
  176.   ----------------------------------------------------------------------------------------------------
  177.   
  178. on getData me,L
  179.   
  180.   -- need a list of arguments to be supplied:
  181.   if ilk(L) <> #propList then return [error:#e1005]
  182.   
  183.   -- also need a dataSet to continue!
  184.   if ilk(dataSet) <> #propList then return [error:#e1006]
  185.   
  186.   -- set specification is needed:
  187.   xSet = L[#set]
  188.   if voidP(xSet) then return [error:#e1007]
  189.   
  190.   -- an item specification is optional:
  191.   xItem = L[#item]
  192.   
  193.   -- set reference must be a symbol:
  194.   if not symbolP(xSet) then return [error:#e1010]
  195.   
  196.   -- extract the list of data items called #xSet:
  197.   xData = dataSet[xSet]
  198.   
  199.   -- the dataSet must exist!
  200.   if ilk(xData) <> #propList then return [error:#e1008]
  201.   
  202.   -- resolve further if an item reference is provided:
  203.   if symbolP(xItem) then
  204.     
  205.     -- extract the data item called #xItem:
  206.     xData = xData[xItem]
  207.     
  208.     -- if an item ref was supplied, then it must resolve to an actual data item:
  209.     if voidP(xData) then return [error:#e1009]
  210.     
  211.   end if
  212.   
  213.   --------------------
  214.   
  215.   -- pass back A COPY OF the data item to the caller:
  216.   if listP(xData) then xData = duplicate(xData)
  217.   return xData
  218.   
  219.   ----------------------------------------------------------------------------------------------------
  220.   
  221. on setDataItem me,L
  222.   
  223.   -- quickie implementation:
  224.   
  225.   -- need a list of arguments to be supplied:
  226.   if ilk(L) <> #propList then return [error:#e1005]
  227.   
  228.   --------------------
  229.   
  230.   -- which set  is to be updated?
  231.   xSet = L[#set]
  232.   
  233.   -- which item  is to be changed?
  234.   xItem = L[#item]
  235.   
  236.   -- what is the new value to be set?
  237.   xValue =  L[#value]
  238.   
  239.   -- extract the list of data items called #xSet:
  240.   xData = dataSet[xSet]
  241.   
  242.   --------------------
  243.   
  244.   -- set the new value:
  245.   xData[xItem] = xValue
  246.   
  247.   ----------------------------------------------------------------------------------------------------